package app.mvc.controller.editor
{
	import app.consts.CommandType;
	import app.interfaces.IEditorCommand;
	
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import utils.UtilsEditorCommand;
	
	/**
	 * UI编辑命令基类
	 * @author xiling
	 */
	public class EditorBaseCommand extends SimpleCommand implements ICommand, IEditorCommand
	{
		protected var _notification:INotification;

		public function EditorBaseCommand()
		{
			super();
		}
		
		public function getNotification():INotification
		{
			return _notification;
		}

		public function set notification(value:INotification):void
		{
			_notification = value;
		}

		public function redo():void
		{
			_notification.setType(CommandType.REDO);
		}
		
		public function undo():void
		{
			_notification.setType(CommandType.UNDO);
		}
		
		override public function execute(notification:INotification):void
		{
			// TODO Auto Generated method stub
			_notification = notification;
			super.execute(notification);
			var type:String = notification.getType();
			if(type!=CommandType.NOT_IN_HISTORY && type!=CommandType.REDO && type!=CommandType.UNDO)
				UtilsEditorCommand.addToHistory(this);
			if(type==CommandType.NORMAL || type==null)
				UtilsEditorCommand.clearRedoCommands();
		}
		
	}
}